package com.hc.bankonline.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class BaseDao {
	
	public Connection getConnection(){
		Connection connection = null;
	
			try {
				Class.forName(MyCons.DRIVER);
				try {
					connection = DriverManager.getConnection(MyCons.URL, MyCons.USER, MyCons.PASSWORD);
				} catch (SQLException e) {
					e.printStackTrace();
				}
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			
	
		return connection;
	}
	
	public void closeAll(Connection connection,PreparedStatement ps,ResultSet rs){
		
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(ps != null){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(connection != null){
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
	
}
